package com.ruoyi.data.es.service.impl;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.data.es.dao.SensorDataRepository;
import com.ruoyi.data.es.domain.SensorData;
import com.ruoyi.data.es.service.SensorDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * @ClassName SensorServiceImpl
 * @Author Iven
 * @Description TODO
 * @Date 2020/12/3 1:42
 */
@Service
public class SensorDataServiceImpl implements SensorDataService {

    @Autowired
    private SensorDataRepository repository;

    @Override
    public Optional<SensorData> findById(String id) {
        return repository.findById(id);
    }

    @Override
    public SensorData save(SensorData sensor) {
        return repository.save(sensor);
    }

    @Override
    public void delete(SensorData sensor) {
        repository.delete(sensor);
    }

    @Override
    public Optional<SensorData> findOne(String id) {
        return repository.findById(id);
    }

    @Override
    public Page<SensorData> findAll() {
        return (Page<SensorData>) repository.findAll();
    }

    @Override
    public Page<SensorData> findByCode(String code, PageRequest pageRequest) {
        return repository.findByCode(code,pageRequest);
    }

    @Override
    public Page<SensorData> findByEquipmentCode(String equipmentCode, PageRequest pageRequest) {
        //todo  es的复杂查询
        // 复杂的查询应该参考  https://cloud.tencent.com/developer/article/1633750  用search方法
        return repository.findByEquipmentCode(equipmentCode,pageRequest);
    }
}
